import objectToQueryString from '../utils/objecToQuery.js'
import request from './index.js'
// 发布帖子
export function publishPost(postInfo) {
	return request.post({
		url: '/posts',
		data: {
			...postInfo
		}
	})
}
// 删除帖子
export function removePost(post_id) {
	return request.delete({
		url: `/posts/${post_id}`
	})
}

// 修改帖子
export function updatePost(post_id, postInfo) {
	return request.post({
		url: `/posts/${post_id}`,
		data: {
			...postInfo
		}
	})
}

// 获取和模糊查询全部帖子帖子
export function getPosts(queryInfo) {
	const queryString = objectToQueryString(queryInfo)
	return request.get({
		url: `/posts?${queryString}`
	})
}
// 根据id查询评论
export function getPostById(post_id) {
	return request.get({
		url: `/posts/single/${post_id}`
	})
}
// 获取帖子评论
export function getComments(post_id) {
	return request.get({
		url: `/comment/${post_id}`
	})
}

// 发布评论
export function publishComment(post_id, content) {
	return request.post({
		url: `/comment`,
		data: {
			post_id,
			content
		}
	})
}

// 回复评论
export function replyComment(post_id, content, parent_id) {
	return request.post({
		url: `/comment/reply`,
		data: {
			post_id,
			content,
			parent_id
		}
	})
}

// 删除评论
export function removeComment(comment_id) {
	return request.delete({
		url: `/comment/${comment_id}`
	})
}

// 根据id查询收藏的人
export function searchFavorityUsers(post_id) {
	return request.get({
		url: `/posts/collection/${post_id}/user`
	})
}

// 根据id查询点赞的人
export function searchLikeUsers(post_id) {
	return request.get({
		url: `/posts/like/${post_id}/user`
	})
}

// 点赞帖子
export function likePost(post_id) {
	return request.put({
		url: `/posts/${post_id}/like`
	})
}
// 收藏帖子
export function collectPost(post_id) {
	return request.put({
		url: `/posts/${post_id}/collection`
	})
}

// 查询自己的收藏
export function queryMyCollection() {
	return request.get({
		url: '/posts/collection'
	})
}


// 查看我发布的帖子
export function queryMyPosts() {
	return request.get({
		url: '/posts/mine/post'
	})
}

// 根据id查找发布的帖子
export function queryPostsByUserId(user_id) {
	return request.get({
		url: `/posts/user/${user_id}/post`
	})
}